<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="utf-8">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="Content-Language" content="UTF-8" />
  <meta content="all" name="robots" />
  <meta name="author" content="tiger"/>
  <meta name="Copyright" content="jinzhou group" />
  <meta name="description" content="jinzhou group oa" />
  <title>生成权限</title>
  <script language="javascript">
    function produce()
    {
	   window.location = "produce_power.php?opt=1";
	}
  </script>
</head>
<body>
<?php
// 加载路径数据
require_once("filepaths.php");
  
$opt = $_GET["opt"];
if (!$opt)
{
?>
  <input type="button" onclick="produce();" value="生成" />
<?php
}
elseif ($opt == 1)
{
   $filename = "data_power.js";
   $datas = array("0: [0, '普通权限', '普通权限', 0]");
   
   include("../../tools/mysql.php");
   db_connect();

   $sql = "SELECT * FROM power WHERE deleted=0 ORDER BY power_id ASC";
   $re = db_query($sql);
   
   foreach ($re as $v)
	 {
		$datas[] = $v["value"] . ": [" . $v["power_id"] . ", '" . $v["name"]
		  . "', '" . $v["name_zh"] . "', " . $v["value"] . "]";
	 }

   $str = "var __powerArray__ = {\n";
   $str .= implode(",\n", $datas);
   $str .= "}\n";
   
   $handle = fopen($file_paths["produced"] . $filename, "w");
   
   if (!fwrite($handle, $str))
	 {
		echo "生成数据文件 " . $file_paths["produced"] . $filename . " 失败！";
	 }
   else 
	 {
		echo "生成数据文件 " . $file_paths["produced"] . $filename . " 成功！";
		copy($file_paths["produced"] . $filename, $file_paths["data_js"] . $filename);
	 }
   
   fclose($handle);
}
?>
</body>
</html>
